// run: $exec < input
#include <cstdio>

int const maxn = 100007;
long long a[maxn];
int n, m, tot;

bool judge(long long t)
{
	int count = m;
	long long s = 0;
	for (int i = 1; i <= tot; i++) {
		s += a[i];
		while (s + i >= t) {
			s -= t - i;
			count--;
			if (count < 0) return 0;
		}
	}
	if (!count) return s <= 0;
	return true;
}

int main()
{
	scanf("%d%d", &n, &m);
	long long sum = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%I64d", &a[i]);
		sum += a[i];
		if (a[i]) tot = i;
	}
	long long l = tot, r = sum + tot;
	while (l + 1 < r) {
		long long mid = (l + r) / 2;
		if (judge(mid)) r = mid;
		else l = mid;
	}
	if (judge(l)) r = l;
	printf("%I64d\n", r);
}

